Cape Town | 26-ITP-Jan | Pretty Taruvinga | Sprint 2 | Data Groups#1109
Cape Town | 26-ITP-Jan | Pretty Taruvinga | Sprint 2 | Data Groups#1109Pretty548 wants to merge 29 commits intoCodeYourFuture:mainfrom
Conversation
2. correct import path for createLookup in tests 3.add jest and configure test script.
This comment has been minimized.
This comment has been minimized.
4 similar comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| const result = {}; | ||
|
|
||
| items.forEach((item) => { | ||
| if (result[item]) { | ||
| result[item]++; | ||
| } else { | ||
| result[item] = 1; | ||
| } | ||
| }); |
There was a problem hiding this comment.
Does the following function call returns the value you expect?
tally(["toString", "toString"]);
Suggestion: Look up an approach to create an empty object with no inherited properties.
There was a problem hiding this comment.
Good catch! I updated the implementation to use Object.create(null) so the result object has no inherited properties. This ensures keys like "toString" are handled correctly.
There was a problem hiding this comment.
The proposed solution is sound, but did you forget to push your changes to GitHub?
| const invert = require("./invert"); | ||
|
|
||
| test("inverts a simple object", () => { | ||
| expect(invert({ a: 1 })).toEqual({ 1: "a" }); | ||
| }); | ||
|
|
||
| test("inverts an object with multiple key-value pairs", () => { | ||
| expect(invert({ a: 1, b: 2 })).toEqual({ | ||
| 1: "a", | ||
| 2: "b", | ||
| }); | ||
| }); | ||
|
|
||
| test("returns empty object when given an empty object", () => { | ||
| expect(invert({})).toEqual({}); | ||
| }); | ||
|
|
||
| test("handles non-string values as keys in the inverted object", () => { | ||
| expect(invert({ a: 1, b: true, c: null })).toEqual({ | ||
| 1: "a", | ||
| true: "b", | ||
| null: "c", | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Shouldn't this be implemented in invert.test.js?
There was a problem hiding this comment.
Good catch, thanks! You're right — these tests should live in invert.test.js. I'll move them there to keep the test structure consistent and separated from implementation.
…om>Move invert tests from invert.js to invert.test.js
This comment has been minimized.
This comment has been minimized.
cjyuan
left a comment
There was a problem hiding this comment.
There are also some unanswered questions in interpret/invert.js.
| const result = {}; | ||
|
|
||
| items.forEach((item) => { | ||
| if (result[item]) { | ||
| result[item]++; | ||
| } else { | ||
| result[item] = 1; | ||
| } | ||
| }); |
There was a problem hiding this comment.
The proposed solution is sound, but did you forget to push your changes to GitHub?
|
Looks good. |
Learners, PR Template
Self checklist
Changelist